<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\controller\Base;
use app\common\library\Ems;
use app\common\library\Sms;
use app\common\model\UserGroup;
use app\common\model\UserRule;
use fast\Random;
use think\Config;
use think\Validate;

/**
 * 角色接口
 */
class Group extends Base
{
    protected $noNeedLogin = ['rules'];
    protected $noNeedRight = ['rules'];


    //角色列表
    public function index()
    {
        $data = UserGroup::getLists();
        $this->success('角色列表',$data);
    }

    //编辑角色
    public function edit()
    {
        repeat_filter();        // 防抖
        $params = $this->request->post();
        $this->apiValidate($params,\app\api\validate\Group::class,'edit');
        $this->success('角色编辑',UserGroup::edit($params));
    }

    //角色删除
    public function del()
    {
        $id = $this->request->post('id');
        if (!$id) {
            $this->error(__('Invalid parameters'));
        }
        if ($id == 1 || $id == 2 || $id == 3) {
            $this->error('默认角色不可删除');
        }
        $this->success('角色删除',UserGroup::del($id));
    }

    //角色规则
    public function rules()
    {
        $data = UserRule::getLists();
        $this->success('角色规则',$data);
    }


}
